<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('通道订单列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            商户名称：<input type="text" name="businessName"/>
                        </li>
                        <li>
                            平台订单号：<input type="text" name="ptOrderno"/>
                        </li>
                        <li>
                            下游订单号：<input type="text" name="childOrderno"/>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            订单状态：<select name="orderStatus">
                            <option value="">所有</option>
                            <option value="0">支付中</option>
                            <option value="1">已支付</option>
                            <option value="2">手动补单</option>
                            <option value="3">已成功,未上分</option>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="channel:channelOrder:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="channel:channelOrder:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('channel:channelOrder:edit')}]];
    var roleKey = [[${roleKey}]];
    var detailFlag = [[${@permission.hasPermi('channel:channelOrder:list')}]];
    var datastatus = [[${@dict.getType('sys_order_status')}]];
    var prefix = ctx + "channel/channelOrder";

    $(function () {
        var options = {
            url: prefix + "/listerror",
            createUrl: prefix + "/add",
            detailUrl: prefix + "/detail/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/exportError",
            modalName: "通道订单",
            sortName: "submitTime",
            sortOrder: "desc",
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'orderId',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'ptOrderno',
                    title: '平台订单号',
                    sortable: true
                },
                {
                    field: 'childOrderno',
                    title: '下游订单号',
                    sortable: true
                },
                {
                    field: 'businessName',
                    title: '商户编号',
                    sortable: true
                },
                {
                    field: 'amount',
                    title: '交易金额',
                    sortable: true
                },
                {
                    field: 'payAmount',
                    title: '实际收款金额',
                    sortable: true
                },
                {
                    field: 'submitTime',
                    title: '提交日期',
                    sortable: true
                },
                {
                    field: 'successTime',
                    title: '成功日期',
                    sortable: true
                },
                {
                    field: 'agentUserName',
                    title: '业务员',
                    sortable: true
                },
                {
                    field: 'account',
                    title: '交易账号',
                    sortable: true
                },
                {
                    field: 'submitUrl',
                    title: '提交地址',
                    visible: false
                },
                {
                    field: 'returnUrl',
                    title: '页面返回地址',
                    visible: false
                },
                {
                    field: 'serverUrl',
                    title: '服务器通知地址',
                    visible: false
                },
                {
                    field: 'orderStatus',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datastatus, value);
                    },
                    sortable: true
                },
                {
                    field: 'status',
                    title: '数据状态',
                    visible: false
                },
                {
                    field: 'createBy',
                    title: '创建者',
                    visible: false
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    visible: false
                },
                {
                    field: 'updateBy',
                    title: '修改者',
                    visible: false
                },
                {
                    field: 'updateTime',
                    title: '修改时间',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if(roleKey == 'admin2' || roleKey == 'admin' || roleKey == 'channel'){
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="#" onclick="reget(\'' + row.orderId + '\',\'' + row.orderStatus + '\')"><i class="fa fa-check"></i>补单</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*已支付*/
    function reget(id, status) {
        if(status == "2"){
            $.modal.alertWarning("补单成功了,无需补单！");
            return;
        }
        var url = prefix + '/edit/' + id;
        $.modal.open("补单操作", url);
    }

    // window.setInterval(function(){
    //     $.table.refresh();
    // }, 5000)
</script>
</body>
</html>